package com.example.piece.vm

import androidx.lifecycle.SavedStateHandle
import com.example.base.ext.LoadingView
import com.example.base.vm.BaseViewModel
import com.example.base.vm.OnSuccess
import com.example.piece.entity.*
import com.example.piece.repository.JokesRepository

class JokesViewModel(savedStateHandle: SavedStateHandle) :
    BaseViewModel<JokesRepository>(savedStateHandle) {
    override fun createRepository(): JokesRepository = JokesRepository()


    /**
     * 1
     * 获取审核列表
     * 需要登录，可以查询你正在审核或者审核失败的段子信息列表
     * @param status 状态 0 审核中 1 审核失败
     * @param page  分页,示例值(1)
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun jokesAuditList(
        loadingView: LoadingView?, status: String, page: String,onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesAuditList(status,page)
        onSuccess(result)
    }

    /**
     * 2
     * 收藏内容-取消收藏
     * @param jokeId 段子id
     * @param status  true 收藏 false 取消收藏
     * @see   Unit
     */
    fun jokesCollect(
        loadingView: LoadingView?, jokeId: String, status: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesCollect(jokeId,status)
        onSuccess(result)
    }

    /**
     * 3
     * 评论段子,一级评论
     * 需要登录，评论成功之后会返回当前你评论的信息，你可以拿到这个信息插入到列表指定位置
     * @param jokeId 段子id
     * @param content  评论的内容
     * @see  JokesCommentEntity
     */
    fun jokesComment(
        loadingView: LoadingView?, jokeId: String, content: String,onSuccess: OnSuccess<JokesCommentEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesComment(jokeId,content)
        onSuccess(result)
    }

    /**
     * 4
     * 删除主评论
     * 需要登录
     * @param commentId 评论id
     * @see  Unit
     */
    fun jokesCommentDelete(
        loadingView: LoadingView?, commentId: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentDelete(commentId)
        onSuccess(result)
    }

    /**
     * 5
     * 添加子评论
     * 需要登录
     * @param commentId  主评论id
     * @param content   评论 内容
     * @param isReplyChild    是否是回复子评论,示例值(false)
     * @see JokesItemCommentListEntity
     */
    fun jokesCommentItem(
        loadingView: LoadingView?, commentId: String, content: String, isReplyChild: Boolean,onSuccess: OnSuccess<JokesItemCommentListEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentItem(commentId, content, isReplyChild)
        onSuccess(result)
    }

    /**
     * 6
     * 删除子评论
     * 需要登录
     * @param commentId  主评论id
     *@see Unit
     */
    fun jokesCommentItemDelete(
        loadingView: LoadingView?, commentId: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentItemDelete(commentId)
        onSuccess(result)
    }

    /**
     * 7
     * 评论 点赞-取消点赞
     * 需要登录
     * @param commentId  主评论id
     *@param status    true 点赞 false 取消点赞
     * @see Unit
     */
    fun jokesCommentLike(
        loadingView: LoadingView?, commentId: String, status: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentLike(commentId,status)
        onSuccess(result)
    }

    /**
     * 8
     * 获取评论列表
     * @param jokeId  段子id
     *@param page    分页,示例值(1)
     * @see JokesCommentListEntity
     */
    fun jokesCommentList(
        loadingView: LoadingView?, jokeId: String, page: String,onSuccess: OnSuccess<JokesCommentListEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentList(jokeId,page)
        onSuccess(result)
    }

    /**
     * 9
     * 获取子评论列表
     * @param commentId  主评论id
     *@param page    分页,示例值(1)
     * @see JokesItemCommentListEntity
     */
    fun jokesCommentListItem(
        loadingView: LoadingView?, commentId: String, page: String,onSuccess: OnSuccess<JokesItemCommentListEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesCommentListItem(commentId,page)
        onSuccess(result)
    }

    /**
     * 10
     * 删除jokes
     * 删除段子
     * @param jokeId      段子id
     * @see Unit
     */
    fun jokesDelete(
        loadingView: LoadingView?, jokeId: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesDelete(jokeId)
        onSuccess(result)
    }

    /**
     * 11
     * 获取收藏状态
     * 用于分享弹窗中显示是否收藏
     * @param jokeId      段子id
     * @see JokesIsCollectEntity
     */
    fun jokesIsCollect(
        loadingView: LoadingView?, jokeId: String,onSuccess: OnSuccess<JokesIsCollectEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesIsCollect(jokeId)
        onSuccess(result)
    }

    /**
     * 12
     * 给段子点赞-取消点赞
     * 需要登录
     * @param id      段子id
     * @param status      true为点赞 false为取消点赞
     * @see Unit

     */
    fun jokesLike(
        loadingView: LoadingView?, id: String, status: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesLike(id,status)
        onSuccess(result)
    }

    /**
     * 13
     * 获取指定id的段子的点赞列表
     * @param jokeId      段子id
     * @param page      分页,示例值(1)
     * @see List<JokesLikeListEntity>
     * @see JokesLikeListEntity

     */
    fun jokesLikeList(
        loadingView: LoadingView?, jokeId: String, page: String,onSuccess: OnSuccess<List<JokesLikeListEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesLikeList(jokeId,page)
        onSuccess(result)
    }
    /**
     * 14
     * 发布段子
     * 需要登录，无论是图片还是视频，都需要上传到七牛云之后拿到接口返回的地址，地址是不带域名的请注意
     * @param content      内容
     * @param image_size      图片尺寸，例如1080x2400，如果是多图，则需要拼接所有的图片尺寸，中间用,分割，比如 480x800,1080x900
     * @param image_urls          如果type为2 此值代表图片列表，中间用,分割
     * @param type      发布类型 1 文本 2 图片 3 视频
     * @param video_duration      视频播放时长
     * @param video_size          视频尺寸 1080x720
     * @param video_thumbnail_url     视频封面
     * @param video_url     视频url，先上传到七牛云之后拿到key
     * @see Unit

     */
    fun jokesPost(
        loadingView: LoadingView?,  content: String,
        image_size: String,
        image_urls: String,
        type: String,
        video_duration: String,
        video_size: String,
        video_thumbnail_url: String,
        video_url: String,onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesPost(content, image_size, image_urls, type, video_duration, video_size, video_thumbnail_url, video_url)
        onSuccess(result)
    }

    /**
     * 15
     * 获取指定id的段子
     * @param jokeId      段子id
     * @see AttentionEntity

     */
    fun jokesTarget(
        loadingView: LoadingView?, jokeId: String, onSuccess: OnSuccess<AttentionEntity>
    ) = Launch(loadingView) {
        val result = repository.jokesTarget(jokeId)
        onSuccess(result)
    }

    /**
     * 16
     * 获取指定用户喜欢的图文段子列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     * @see List<AttentionEntity>
     * @see  AttentionEntity

     */
    fun jokesTextPicJokesLikeList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesTextPicJokesLikeList(targetUserId,page)
        onSuccess(result)
    }

    /**
     * 17
     * 获取指定用户图文段子列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     * @see List<AttentionEntity>
     * @see AttentionEntity
     *

     */
    fun jokesTextPicJokesList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesTextPicJokesList(targetUserId,page)
        onSuccess(result)
    }
    /**
     * 18
     * 踩段子-取消踩段子
     * 需要登录
     * @param id      段子id
     * @param status true为踩 false为取消踩
     * @see Unit
     *
     *

     */
    fun jokesUnlike(
        loadingView: LoadingView?, id: String,status: String, onSuccess: OnSuccess<Unit>
    ) = Launch(loadingView) {
        val result = repository.jokesUnlike(id,status)
        onSuccess(result)
    }

    /**
     * 19
     * 获取指定用户喜欢的视频列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     * @see List<JokesVideoLikeListEntity>
     * @see JokesVideoLikeListEntity

     */
    fun jokesVideoLikeList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<JokesVideoLikeListEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesVideoLikeList(targetUserId,page)
        onSuccess(result)
    }

    /**
     * 20
     * 获取指定用户所有视频列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     *
     * @see List<JokesVideoLikeListEntity>
     * @see JokesVideoLikeListEntity
     *

     */
    fun jokesVideoList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<JokesVideoLikeListEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesVideoList(targetUserId,page)
        onSuccess(result)
    }

    /**
     * 21
     * 获取指定id对应视频列表
     * @param ids      段子id列表，中间用,分割
     * @see List<AttentionEntity>
     * @see AttentionEntity

     */
    fun jokesVideoListIds(
        loadingView: LoadingView?, ids: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesVideoListIds(ids)
        onSuccess(result)
    }

    /**
     * 22
     * 获取指定用户喜欢的段子列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     * @see  List<AttentionEntity>
     * @see    AttentionEntity

     */
    fun jokesWholeJokesLikeList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesWholeJokesLikeList(targetUserId,page)
        onSuccess(result)
    }

    /**
     * 23
     * 获取指定用户段子列表
     * @param targetUserId      用户id
     * @param page 分页,示例值(1)
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun jokesWholeJokesList(
        loadingView: LoadingView?, targetUserId: String,page: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesWholeJokesList(targetUserId,page)
        onSuccess(result)
    }
}